const  FS = require('fs'),  Path = require('path'),
       Utility = require('../libs/utility');


module.exports = function () {

    var file = this.request.files[0].data;

    var path = Utility.fromCWD(`public/${file.type.split('/')[0]}`);

    if (! FS.existsSync( path ))  FS.mkdirSync( path );

    path = Path.join(path, file.name);

    FS.renameSync(file.path, path);

    return path;
};